package com.ruoyi.generator.controller;


import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.generator.po.*;
import com.ruoyi.generator.service.InspectionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.ruoyi.common.utils.PageUtils.startPage;

@RestController
@RequestMapping("/inspection")
public class InspectionController extends BaseController {

    @Autowired
    private InspectionService inspectionService;

    @GetMapping("/db/list")
    public TableDataInfo list()
    {

        List<ScheduleShift> list = inspectionService.selectScheduleList();
        return getDataTable(list);
    }

    @GetMapping("/db/getUser")
    public SysUser getUser()
    {
        SysUser user = inspectionService.getUser();
        return user;
    }

    @GetMapping("/db/deviceList")
    public TableDataInfo deviceList(Device device)
    {
        startPage();
        List<Device> list = inspectionService.selectDeviceList(device);
        return getDataTable(list);
    }

    @GetMapping("/db/getSchedules")
    public TableDataInfo getSchedules()
    {
        System.out.println("device:");
        List<WushuiSchedule> list = inspectionService.getSchedules();
        return getDataTable(list);
    }

    @GetMapping("/db/getDepts")
    public TableDataInfo getDepts()
    {
        System.out.println("device:");
        List<SysDept> list = inspectionService.getDepts();
        return getDataTable(list);
    }

    @GetMapping("/db/getUsers")
    public TableDataInfo getUsers()
    {
        System.out.println("device:");
        List<SysUser> list = inspectionService.getUsers();
        return getDataTable(list);
    }

    @PostMapping("/db/saveEdit")
    public AjaxResult saveEdit(@RequestBody ScheduleShift scheduleShift)
    {
        System.out.println("scheduleShift:"+scheduleShift);
        return inspectionService.saveEdit(scheduleShift);
    }
    @PostMapping("/db/inspectionRecordUpload")
    public AjaxResult inspectionRecordUpload(@RequestBody InspectionRecord inspectionRecord)
    {
        System.out.println("inspectionRecord:"+inspectionRecord);
        return inspectionService.inspectionRecordUpload(inspectionRecord);
    }
    @PostMapping("/db/faultDeclaration")
    public AjaxResult faultDeclaration(@RequestBody FaultDeclaration  faultDeclaration)
    {
        System.out.println("faultDeclaration:"+faultDeclaration);
        return inspectionService.faultDeclaration(faultDeclaration);
    }
    @PostMapping("/db/addCheckingPlan")
    public AjaxResult addCheckingPlan(@RequestBody CheckingPlan checkingPlan)
    {
        return inspectionService.addCheckingPlan(checkingPlan);
    }

    @GetMapping(value = "/db/getPlan")
    public TableDataInfo getPlan(String planName)
    {
        System.out.println("planName:"+planName);
        List<SpotCheckPlan> plan =inspectionService.getPlan(planName);
        return getDataTable(plan);
    }
    @GetMapping(value = "/db/getFaultDeclaration")
    public TableDataInfo getFaultDeclaration()
    {
        List<FaultDeclaration> plan =inspectionService.getFaultDeclaration();
        return getDataTable(plan);
    }
    @GetMapping(value = "/db/getInspectionRecord")
    public TableDataInfo getInspectionRecord()
    {
        List<InspectionRecord> plan =inspectionService.getInspectionRecord();
        return getDataTable(plan);
    }

    @GetMapping(value = "/db/restore/{period}")
    public AjaxResult restore(@PathVariable String period)
    {
        return success(inspectionService.restore(period));
    }

}
